<template>
	<view class="user-promote-order">
		<tabs :active="active" :line-width="40" @change="onChange"
			:config="{activeColor: '#24A3FF', underLineColor: '#24A3FF'}">
			<tab v-for="(item, index) in order" :key="index" :title="item.name">
				<order-item class="mt20" v-if="item.isShow" :type="item.type"></order-item>
			</tab>
		</tabs>
	</view>
</template>

<script>
	import {
		userOrderPromoteOrder
	} from "@/utils/type";
	import orderItem from "../../components/order-item/index.vue"

	export default {
		components: {
			orderItem
		},
		data() {
			return {
				type: 1, // 1: 我的订单 2: 团队订单
				order: [{
					name: "全部",
					type: userOrderPromoteOrder.ALL,
					isShow: false
				}, {
					name: "租赁订单",
					type: userOrderPromoteOrder.WAIT_RETURN,
					isShow: false
				}, {
					name: "租售订单",
					type: userOrderPromoteOrder.HANDLED,
					isShow: false
				}, {
					name: "已结算",
					type: userOrderPromoteOrder.INVALED,
					isShow: false
				}],
				active: userOrderPromoteOrder.ALL
			};
		},

		components: {

		},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.type = optinos.type
			switch (options.type) {
				case 1:
					uni.setNavigationBarTitle({
						title: '我的订单'
					})
					break
				case 2:
					uni.setNavigationBarTitle({
						title: '团队订单'
					})
					break
			}
			let type = parseInt(options.type) || userOrderPromoteOrder.ALL;
			this.changeShow(type);
		},

		methods: {
			onChange(e) {
				this.changeShow(e);
			},

			changeShow(type) {
				const {
					order
				} = this;
				console.log('changeShow');
				let index = order.findIndex(item => {
					return item.type == type;
				});
				console.log(index);

				if (index != -1) {
					this.active = type;
					this.order[index].isShow = true
					console.log(this.order[index].isShow);
				}
			}

		}
	};
</script>
<style>

</style>